package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;

public class Biblioteca {
    PrintStream printStream;
    BufferedReader bufferedReader;
    List<LibraryBook> bookList;
    private Menu menu;
    private ListBookCommand listBookCommand;

    public Biblioteca(PrintStream printStream, List<LibraryBook> bookList, BufferedReader bufferedReader, Menu menu) {
        this.printStream = printStream;
        this.bookList = bookList;
        this.bufferedReader = bufferedReader;
        this.menu = menu;
        listBookCommand = new ListBookCommand(printStream, bookList);
    }

    public void run(){
        displayWelcomeMessage();
        listBookCommand.listBooks();
        while(true){
            try {
                String choice = menu.run();
                if (choice.equals("4")){
                    printStream.println("GoodBye");
                    break;
                }
                menu.executeUserChoice(choice);
            } catch (IOException e) {
                printStream.println("Error Reading Input");
            }
        }
    }

    public void displayWelcomeMessage() {
        printStream.println("Welcome to Biblioteca!");
    }

    public String getUserOptionChoice() throws IOException {
        return bufferedReader.readLine();
    }

}
